<!DOCTYPE html><html><head>
<title>struct::graph - Tcl Data Structures</title>
<style type="text/css"><!--
    HTML {
	background: 	#FFFFFF;
	color: 		black;
    }
    BODY {
	background: 	#FFFFFF;
	color:	 	black;
    }
    DIV.doctools {
	margin-left:	10%;
	margin-right:	10%;
    }
    DIV.doctools H1,DIV.doctools H2 {
	margin-left:	-5%;
    }
    H1, H2, H3, H4 {
	margin-top: 	1em;
	font-family:	sans-serif;
	font-size:	large;
	color:		#005A9C;
	background: 	transparent;
	text-align:		left;
    }
    H1.doctools_title {
	text-align: center;
    }
    UL,OL {
	margin-right: 0em;
	margin-top: 3pt;
	margin-bottom: 3pt;
    }
    UL LI {
	list-style: disc;
    }
    OL LI {
	list-style: decimal;
    }
    DT {
	padding-top: 	1ex;
    }
    UL.doctools_toc,UL.doctools_toc UL, UL.doctools_toc UL UL {
	font:		normal 12pt/14pt sans-serif;
	list-style:	none;
    }
    LI.doctools_section, LI.doctools_subsection {
	list-style: 	none;
	margin-left: 	0em;
	text-indent:	0em;
	padding: 	0em;
    }
    PRE {
	display: 	block;
	font-family:	monospace;
	white-space:	pre;
	margin:		0%;
	padding-top:	0.5ex;
	padding-bottom:	0.5ex;
	padding-left:	1ex;
	padding-right:	1ex;
	width:		100%;
    }
    PRE.doctools_example {
	color: 		black;
	background: 	#f5dcb3;
	border:		1px solid black;
    }
    UL.doctools_requirements LI, UL.doctools_syntax LI {
	list-style: 	none;
	margin-left: 	0em;
	text-indent:	0em;
	padding:	0em;
    }
    DIV.doctools_synopsis {
	color: 		black;
	background: 	#80ffff;
	border:		1px solid black;
	font-family:	serif;
	margin-top: 	1em;
	margin-bottom: 	1em;
    }
    UL.doctools_syntax {
	margin-top: 	1em;
	border-top:	1px solid black;
    }
    UL.doctools_requirements {
	margin-bottom: 	1em;
	border-bottom:	1px solid black;
    }
--></style>
</head>
<!-- Generated from file 'graph.man' by tcllib/doctools with format 'html'
   -->
<!-- Copyright &amp;copy; 2002-2009,2019 Andreas Kupries &amp;lt;andreas_kupries@users.sourceforge.net&amp;gt;
   -->
<!-- struct::graph.n
   -->
<body><hr> [
   <a href="../../../../../../../../home">Tcllib Home</a>
&#124; <a href="../../../../toc.html">Main Table Of Contents</a>
&#124; <a href="../../../toc.html">Table Of Contents</a>
&#124; <a href="../../../../index.html">Keyword Index</a>
&#124; <a href="../../../../toc0.html">Categories</a>
&#124; <a href="../../../../toc1.html">Modules</a>
&#124; <a href="../../../../toc2.html">Applications</a>
 ] <hr>
<div class="doctools">
<h1 class="doctools_title">struct::graph(n) 2.4.3 tcllib &quot;Tcl Data Structures&quot;</h1>
<div id="name" class="doctools_section"><h2><a name="name">Name</a></h2>
<p>struct::graph - Create and manipulate directed graph objects</p>
</div>
<div id="toc" class="doctools_section"><h2><a name="toc">Table Of Contents</a></h2>
<ul class="doctools_toc">
<li class="doctools_section"><a href="#toc">Table Of Contents</a></li>
<li class="doctools_section"><a href="#synopsis">Synopsis</a></li>
<li class="doctools_section"><a href="#section1">Description</a></li>
<li class="doctools_section"><a href="#section2">Changes for 2.0</a></li>
<li class="doctools_section"><a href="#section3">Bugs, Ideas, Feedback</a></li>
<li class="doctools_section"><a href="#keywords">Keywords</a></li>
<li class="doctools_section"><a href="#category">Category</a></li>
<li class="doctools_section"><a href="#copyright">Copyright</a></li>
</ul>
</div>
<div id="synopsis" class="doctools_section"><h2><a name="synopsis">Synopsis</a></h2>
<div class="doctools_synopsis">
<ul class="doctools_requirements">
<li>package require <b class="pkgname">Tcl 8.4</b></li>
<li>package require <b class="pkgname">struct::graph <span class="opt">?2.4.3?</span></b></li>
<li>package require <b class="pkgname">struct::list <span class="opt">?1.5?</span></b></li>
<li>package require <b class="pkgname">struct::set <span class="opt">?2.2.3?</span></b></li>
</ul>
<ul class="doctools_syntax">
<li><a href="#1"><b class="cmd">::struct::graph</b> <span class="opt">?<i class="arg">graphName</i>?</span> <span class="opt">?<b class="const">=</b>|<b class="const">:=</b>|<b class="const">as</b>|<b class="const">deserialize</b> <i class="arg">source</i>?</span></a></li>
<li><a href="#2"><b class="cmd">graphName</b> <i class="arg">option</i> <span class="opt">?<i class="arg">arg arg ...</i>?</span></a></li>
<li><a href="#3"><i class="arg">graphName</i> <b class="method">=</b> <i class="arg">sourcegraph</i></a></li>
<li><a href="#4"><i class="arg">graphName</i> <b class="method">--&gt;</b> <i class="arg">destgraph</i></a></li>
<li><a href="#5"><i class="arg">graphName</i> <b class="method">append</b> <i class="arg">key</i> <i class="arg">value</i></a></li>
<li><a href="#6"><i class="arg">graphName</i> <b class="method">deserialize</b> <i class="arg">serialization</i></a></li>
<li><a href="#7"><i class="arg">graphName</i> <b class="method">destroy</b></a></li>
<li><a href="#8"><i class="arg">graphName</i> <b class="method">arc append</b> <i class="arg">arc</i> <i class="arg">key</i> <i class="arg">value</i></a></li>
<li><a href="#9"><i class="arg">graphName</i> <b class="method">arc attr</b> <i class="arg">key</i></a></li>
<li><a href="#10"><i class="arg">graphName</i> <b class="method">arc attr</b> <i class="arg">key</i> <b class="option">-arcs</b> <i class="arg">list</i></a></li>
<li><a href="#11"><i class="arg">graphName</i> <b class="method">arc attr</b> <i class="arg">key</i> <b class="option">-glob</b> <i class="arg">globpattern</i></a></li>
<li><a href="#12"><i class="arg">graphName</i> <b class="method">arc attr</b> <i class="arg">key</i> <b class="option">-regexp</b> <i class="arg">repattern</i></a></li>
<li><a href="#13"><i class="arg">graphName</i> <b class="method">arc delete</b> <i class="arg">arc</i> <span class="opt">?<i class="arg">arc</i> ...?</span></a></li>
<li><a href="#14"><i class="arg">graphName</i> <b class="method">arc exists</b> <i class="arg">arc</i></a></li>
<li><a href="#15"><i class="arg">graphName</i> <b class="method">arc flip</b> <i class="arg">arc</i></a></li>
<li><a href="#16"><i class="arg">graphName</i> <b class="method">arc get</b> <i class="arg">arc</i> <i class="arg">key</i></a></li>
<li><a href="#17"><i class="arg">graphName</i> <b class="method">arc getall</b> <i class="arg">arc</i> <span class="opt">?<i class="arg">pattern</i>?</span></a></li>
<li><a href="#18"><i class="arg">graphName</i> <b class="method">arc getunweighted</b></a></li>
<li><a href="#19"><i class="arg">graphName</i> <b class="method">arc getweight</b> <i class="arg">arc</i></a></li>
<li><a href="#20"><i class="arg">graphName</i> <b class="method">arc keys</b> <i class="arg">arc</i> <span class="opt">?<i class="arg">pattern</i>?</span></a></li>
<li><a href="#21"><i class="arg">graphName</i> <b class="method">arc keyexists</b> <i class="arg">arc</i> <i class="arg">key</i></a></li>
<li><a href="#22"><i class="arg">graphName</i> <b class="method">arc insert</b> <i class="arg">start</i> <i class="arg">end</i> <span class="opt">?<i class="arg">child</i>?</span></a></li>
<li><a href="#23"><i class="arg">graphName</i> <b class="method">arc lappend</b> <i class="arg">arc</i> <i class="arg">key</i> <i class="arg">value</i></a></li>
<li><a href="#24"><i class="arg">graphName</i> <b class="method">arc rename</b> <i class="arg">arc</i> <i class="arg">newname</i></a></li>
<li><a href="#25"><i class="arg">graphName</i> <b class="method">arc set</b> <i class="arg">arc</i> <i class="arg">key</i> <span class="opt">?<i class="arg">value</i>?</span></a></li>
<li><a href="#26"><i class="arg">graphName</i> <b class="method">arc setunweighted</b> <span class="opt">?<i class="arg">weight</i>?</span></a></li>
<li><a href="#27"><i class="arg">graphName</i> <b class="method">arc setweight</b> <i class="arg">arc</i> <i class="arg">weight</i></a></li>
<li><a href="#28"><i class="arg">graphName</i> <b class="method">arc unsetweight</b> <i class="arg">arc</i></a></li>
<li><a href="#29"><i class="arg">graphName</i> <b class="method">arc hasweight</b> <i class="arg">arc</i></a></li>
<li><a href="#30"><i class="arg">graphName</i> <b class="method">arc source</b> <i class="arg">arc</i></a></li>
<li><a href="#31"><i class="arg">graphName</i> <b class="method">arc target</b> <i class="arg">arc</i></a></li>
<li><a href="#32"><i class="arg">graphName</i> <b class="method">arc nodes</b> <i class="arg">arc</i></a></li>
<li><a href="#33"><i class="arg">graphName</i> <b class="method">arc move-source</b> <i class="arg">arc</i> <i class="arg">newsource</i></a></li>
<li><a href="#34"><i class="arg">graphName</i> <b class="method">arc move-target</b> <i class="arg">arc</i> <i class="arg">newtarget</i></a></li>
<li><a href="#35"><i class="arg">graphName</i> <b class="method">arc move</b> <i class="arg">arc</i> <i class="arg">newsource</i> <i class="arg">newtarget</i></a></li>
<li><a href="#36"><i class="arg">graphName</i> <b class="method">arc unset</b> <i class="arg">arc</i> <i class="arg">key</i></a></li>
<li><a href="#37"><i class="arg">graphName</i> <b class="method">arc weights</b></a></li>
<li><a href="#38"><i class="arg">graphName</i> <b class="method">arcs</b> <span class="opt">?-key <i class="arg">key</i>?</span> <span class="opt">?-value <i class="arg">value</i>?</span> <span class="opt">?-filter <i class="arg">cmdprefix</i>?</span> <span class="opt">?-in|-out|-adj|-inner|-embedding <i class="arg">node node...</i>?</span></a></li>
<li><a href="#39"><i class="arg">graphName</i> <b class="method">lappend</b> <i class="arg">key</i> <i class="arg">value</i></a></li>
<li><a href="#40"><i class="arg">graphName</i> <b class="method">node append</b> <i class="arg">node</i> <i class="arg">key</i> <i class="arg">value</i></a></li>
<li><a href="#41"><i class="arg">graphName</i> <b class="method">node attr</b> <i class="arg">key</i></a></li>
<li><a href="#42"><i class="arg">graphName</i> <b class="method">node attr</b> <i class="arg">key</i> <b class="option">-nodes</b> <i class="arg">list</i></a></li>
<li><a href="#43"><i class="arg">graphName</i> <b class="method">node attr</b> <i class="arg">key</i> <b class="option">-glob</b> <i class="arg">globpattern</i></a></li>
<li><a href="#44"><i class="arg">graphName</i> <b class="method">node attr</b> <i class="arg">key</i> <b class="option">-regexp</b> <i class="arg">repattern</i></a></li>
<li><a href="#45"><i class="arg">graphName</i> <b class="method">node degree</b> <span class="opt">?-in|-out?</span> <i class="arg">node</i></a></li>
<li><a href="#46"><i class="arg">graphName</i> <b class="method">node delete</b> <i class="arg">node</i> <span class="opt">?<i class="arg">node</i>...?</span></a></li>
<li><a href="#47"><i class="arg">graphName</i> <b class="method">node exists</b> <i class="arg">node</i></a></li>
<li><a href="#48"><i class="arg">graphName</i> <b class="method">node get</b> <i class="arg">node</i> <i class="arg">key</i></a></li>
<li><a href="#49"><i class="arg">graphName</i> <b class="method">node getall</b> <i class="arg">node</i> <span class="opt">?<i class="arg">pattern</i>?</span></a></li>
<li><a href="#50"><i class="arg">graphName</i> <b class="method">node keys</b> <i class="arg">node</i> <span class="opt">?<i class="arg">pattern</i>?</span></a></li>
<li><a href="#51"><i class="arg">graphName</i> <b class="method">node keyexists</b> <i class="arg">node</i> <i class="arg">key</i></a></li>
<li><a href="#52"><i class="arg">graphName</i> <b class="method">node insert</b> <span class="opt">?<i class="arg">node</i>...?</span></a></li>
<li><a href="#53"><i class="arg">graphName</i> <b class="method">node lappend</b> <i class="arg">node</i> <i class="arg">key</i> <i class="arg">value</i></a></li>
<li><a href="#54"><i class="arg">graphName</i> <b class="method">node opposite</b> <i class="arg">node</i> <i class="arg">arc</i></a></li>
<li><a href="#55"><i class="arg">graphName</i> <b class="method">node rename</b> <i class="arg">node</i> <i class="arg">newname</i></a></li>
<li><a href="#56"><i class="arg">graphName</i> <b class="method">node set</b> <i class="arg">node</i> <i class="arg">key</i> <span class="opt">?<i class="arg">value</i>?</span></a></li>
<li><a href="#57"><i class="arg">graphName</i> <b class="method">node unset</b> <i class="arg">node</i> <i class="arg">key</i></a></li>
<li><a href="#58"><i class="arg">graphName</i> <b class="method">nodes</b> <span class="opt">?-key <i class="arg">key</i>?</span> <span class="opt">?-value <i class="arg">value</i>?</span> <span class="opt">?-filter <i class="arg">cmdprefix</i>?</span> <span class="opt">?-in|-out|-adj|-inner|-embedding <i class="arg">node</i> <i class="arg">node</i>...?</span></a></li>
<li><a href="#59"><i class="arg">graphName</i> <b class="method">get</b> <i class="arg">key</i></a></li>
<li><a href="#60"><i class="arg">graphName</i> <b class="method">getall</b> <span class="opt">?<i class="arg">pattern</i>?</span></a></li>
<li><a href="#61"><i class="arg">graphName</i> <b class="method">keys</b> <span class="opt">?<i class="arg">pattern</i>?</span></a></li>
<li><a href="#62"><i class="arg">graphName</i> <b class="method">keyexists</b> <i class="arg">key</i></a></li>
<li><a href="#63"><i class="arg">graphName</i> <b class="method">serialize</b> <span class="opt">?<i class="arg">node</i>...?</span></a></li>
<li><a href="#64"><i class="arg">graphName</i> <b class="method">set</b> <i class="arg">key</i> <span class="opt">?<i class="arg">value</i>?</span></a></li>
<li><a href="#65"><i class="arg">graphName</i> <b class="method">swap</b> <i class="arg">node1</i> <i class="arg">node2</i></a></li>
<li><a href="#66"><i class="arg">graphName</i> <b class="method">unset</b> <i class="arg">key</i></a></li>
<li><a href="#67"><i class="arg">graphName</i> <b class="method">walk</b> <i class="arg">node</i> <span class="opt">?-order <i class="arg">order</i>?</span> <span class="opt">?-type <i class="arg">type</i>?</span> <span class="opt">?-dir <i class="arg">direction</i>?</span> -command <i class="arg">cmd</i></a></li>
</ul>
</div>
</div>
<div id="section1" class="doctools_section"><h2><a name="section1">Description</a></h2>
<p>A directed graph is a structure containing two collections of
elements, called <i class="term">nodes</i> and <i class="term">arcs</i> respectively, together
with a relation (&quot;connectivity&quot;) that places a general structure upon
the nodes and arcs.</p>
<p>Each arc is connected to two nodes, one of which is called the
<i class="term"><a href="../../../../index.html#source">source</a></i> and the other the <i class="term">target</i>. This imposes a
direction upon the arc, which is said to go from the source to the
target. It is allowed that source and target of an arc are the same
node. Such an arc is called a <i class="term"><a href="../../../../index.html#loop">loop</a></i>.
Whenever a node is either the source or target of an arc both are said
to be <i class="term"><a href="../../../../index.html#adjacent">adjacent</a></i>. This extends into a relation between nodes,
i.e. if two nodes are connected through at least one arc they are said
to be <i class="term"><a href="../../../../index.html#adjacent">adjacent</a></i> too.</p>
<p>Each node can be the source and target for any number of arcs. The
former are called the <i class="term">outgoing arcs</i> of the node, the latter
the <i class="term">incoming arcs</i> of the node. The number of arcs in either
set is called the <i class="term">in-degree</i> resp. the <i class="term">out-degree</i> of the
node.</p>
<p>In addition to maintaining the node and arc relationships, this graph
implementation allows any number of named <i class="term">attributes</i> to be
associated with the graph itself, and each node or arc.</p>
<p><em>Note:</em> The major version of the package <b class="package"><a href="../../../../index.html#struct">struct</a></b> has
been changed to version 2.0, due to backward incompatible changes in
the API of this module. Please read the section
<span class="sectref"><a href="#section2">Changes for 2.0</a></span> for a full list of all changes,
incompatible and otherwise.</p>
<p><em>Note:</em> A C-implementation of the command can be had from the
location <a href="http://www.purl.org/NET/schlenker/tcl/cgraph">http://www.purl.org/NET/schlenker/tcl/cgraph</a>. See also
<a href="http://wiki.tcl.tk/cgraph">http://wiki.tcl.tk/cgraph</a>.  This implementation uses a bit less
memory than the tcl version provided here directly, and is faster. Its
support is limited to versions of the package before 2.0.</p>
<p>As of version 2.2 of this package a critcl based C implementation is
available from here as well. This implementation however requires Tcl
8.4 to run.</p>
<p>The main command of the package is:</p>
<dl class="doctools_definitions">
<dt><a name="1"><b class="cmd">::struct::graph</b> <span class="opt">?<i class="arg">graphName</i>?</span> <span class="opt">?<b class="const">=</b>|<b class="const">:=</b>|<b class="const">as</b>|<b class="const">deserialize</b> <i class="arg">source</i>?</span></a></dt>
<dd><p>The command creates a new graph object with an associated global Tcl
command whose name is <i class="arg">graphName</i>.  This command may be used to
invoke various operations on the graph.  It has the following general
form:</p>
<dl class="doctools_definitions">
<dt><a name="2"><b class="cmd">graphName</b> <i class="arg">option</i> <span class="opt">?<i class="arg">arg arg ...</i>?</span></a></dt>
<dd><p><i class="arg">Option</i> and the <i class="arg">arg</i>s determine the exact behavior of the
command.</p></dd>
</dl>
<p>If <i class="arg">graphName</i> is not specified a unique name will be generated by
the package itself. If a <i class="arg">source</i> is specified the new graph will
be initialized to it. For the operators <b class="const">=</b>, <b class="const">:=</b>, and
<b class="const">as</b> the <i class="arg">source</i> argument is interpreted as the name of
another graph object, and the assignment operator <b class="method">=</b> will be
executed. For the operator <b class="const">deserialize</b> the <i class="arg">source</i> is a
serialized graph object and <b class="method">deserialize</b> will be executed.</p>
<p>In other words</p>
<pre class="doctools_example">
    ::struct::graph mygraph = b
</pre>
<p>is equivalent to</p>
<pre class="doctools_example">
    ::struct::graph mygraph
    mygraph = b
</pre>
<p>and</p>
<pre class="doctools_example">
    ::struct::graph mygraph deserialize $b
</pre>
<p>is equivalent to</p>
<pre class="doctools_example">
    ::struct::graph mygraph
    mygraph deserialize $b
</pre>
</dd>
</dl>
<p>The following commands are possible for graph objects:</p>
<dl class="doctools_definitions">
<dt><a name="3"><i class="arg">graphName</i> <b class="method">=</b> <i class="arg">sourcegraph</i></a></dt>
<dd><p>This is the <i class="term">assignment</i> operator for graph objects. It copies
the graph contained in the graph object <i class="arg">sourcegraph</i> over the
graph data in <i class="arg">graphName</i>. The old contents of <i class="arg">graphName</i> are
deleted by this operation.</p>
<p>This operation is in effect equivalent to</p>
<pre class="doctools_example">
    <i class="arg">graphName</i> <b class="method">deserialize</b> [<i class="arg">sourcegraph</i> <b class="method">serialize</b>]
</pre>
<p>The operation assumes that the <i class="arg">sourcegraph</i> provides the method
<b class="method">serialize</b> and that this method returns a valid graph
serialization.</p></dd>
<dt><a name="4"><i class="arg">graphName</i> <b class="method">--&gt;</b> <i class="arg">destgraph</i></a></dt>
<dd><p>This is the <i class="term">reverse assignment</i> operator for graph objects. It
copies the graph contained in the graph object <i class="arg">graphName</i> over
the graph data in the object <i class="arg">destgraph</i>.
The old contents of <i class="arg">destgraph</i> are deleted by this operation.</p>
<p>This operation is in effect equivalent to</p>
<pre class="doctools_example">
    <i class="arg">destgraph</i> <b class="method">deserialize</b> [<i class="arg">graphName</i> <b class="method">serialize</b>]
</pre>
<p>The operation assumes that the <i class="arg">destgraph</i> provides the method
<b class="method">deserialize</b> and that this method takes a graph serialization.</p></dd>
<dt><a name="5"><i class="arg">graphName</i> <b class="method">append</b> <i class="arg">key</i> <i class="arg">value</i></a></dt>
<dd><p>Appends a <i class="arg">value</i> to one of the keyed values associated with the graph.
Returns the new value given to the attribute <i class="arg">key</i>.</p></dd>
<dt><a name="6"><i class="arg">graphName</i> <b class="method">deserialize</b> <i class="arg">serialization</i></a></dt>
<dd><p>This is the complement to <b class="method">serialize</b>. It replaces the graph
data in <i class="arg">graphName</i> with the graph described by the
<i class="arg">serialization</i> value. The old contents of <i class="arg">graphName</i> are
deleted by this operation.</p></dd>
<dt><a name="7"><i class="arg">graphName</i> <b class="method">destroy</b></a></dt>
<dd><p>Destroys the graph, including its storage space and associated command.</p></dd>
<dt><a name="8"><i class="arg">graphName</i> <b class="method">arc append</b> <i class="arg">arc</i> <i class="arg">key</i> <i class="arg">value</i></a></dt>
<dd><p>Appends a <i class="arg">value</i> to one of the keyed values associated with an
<i class="arg">arc</i>. Returns the new value given to the attribute <i class="arg">key</i>.</p></dd>
<dt><a name="9"><i class="arg">graphName</i> <b class="method">arc attr</b> <i class="arg">key</i></a></dt>
<dd></dd>
<dt><a name="10"><i class="arg">graphName</i> <b class="method">arc attr</b> <i class="arg">key</i> <b class="option">-arcs</b> <i class="arg">list</i></a></dt>
<dd></dd>
<dt><a name="11"><i class="arg">graphName</i> <b class="method">arc attr</b> <i class="arg">key</i> <b class="option">-glob</b> <i class="arg">globpattern</i></a></dt>
<dd></dd>
<dt><a name="12"><i class="arg">graphName</i> <b class="method">arc attr</b> <i class="arg">key</i> <b class="option">-regexp</b> <i class="arg">repattern</i></a></dt>
<dd><p>This method retrieves the value of the attribute named <i class="arg">key</i>, for
all arcs in the graph (matching the restriction specified via one of
the possible options) and having the specified attribute.</p>
<p>The result is a dictionary mapping from arc names to the value of
attribute <i class="arg">key</i> at that arc.
Arcs not having the attribute <i class="arg">key</i>, or not passing a
specified restriction, are not listed in the result.</p>
<p>The possible restrictions are:</p>
<dl class="doctools_options">
<dt><b class="option">-arcs</b></dt>
<dd><p>The value is a list of arcs. Only the arcs mentioned in this list
are searched for the attribute.</p></dd>
<dt><b class="option">-glob</b></dt>
<dd><p>The value is a glob pattern. Only the arcs in the graph whose names
match this pattern are searched for the attribute.</p></dd>
<dt><b class="option">-regexp</b></dt>
<dd><p>The value is a regular expression. Only the arcs in the graph whose
names match this pattern are searched for the attribute.</p></dd>
</dl></dd>
<dt><a name="13"><i class="arg">graphName</i> <b class="method">arc delete</b> <i class="arg">arc</i> <span class="opt">?<i class="arg">arc</i> ...?</span></a></dt>
<dd><p>Remove the specified arcs from the graph.</p></dd>
<dt><a name="14"><i class="arg">graphName</i> <b class="method">arc exists</b> <i class="arg">arc</i></a></dt>
<dd><p>Return true if the specified <i class="arg">arc</i> exists in the graph.</p></dd>
<dt><a name="15"><i class="arg">graphName</i> <b class="method">arc flip</b> <i class="arg">arc</i></a></dt>
<dd><p>Reverses the direction of the named <i class="arg">arc</i>, i.e. the source and
target nodes of the arc are exchanged with each other.</p></dd>
<dt><a name="16"><i class="arg">graphName</i> <b class="method">arc get</b> <i class="arg">arc</i> <i class="arg">key</i></a></dt>
<dd><p>Returns the value associated with the key <i class="arg">key</i> for the <i class="arg">arc</i>.</p></dd>
<dt><a name="17"><i class="arg">graphName</i> <b class="method">arc getall</b> <i class="arg">arc</i> <span class="opt">?<i class="arg">pattern</i>?</span></a></dt>
<dd><p>Returns a dictionary (suitable for use with [<b class="cmd">array set</b>])
for the <i class="arg">arc</i>.
If the <i class="arg">pattern</i> is specified only the attributes whose names
match the pattern will be part of the returned dictionary. The pattern
is a <b class="cmd">glob</b> pattern.</p></dd>
<dt><a name="18"><i class="arg">graphName</i> <b class="method">arc getunweighted</b></a></dt>
<dd><p>Returns a list containing the names of all arcs in the graph which
have no weight associated with them.</p></dd>
<dt><a name="19"><i class="arg">graphName</i> <b class="method">arc getweight</b> <i class="arg">arc</i></a></dt>
<dd><p>Returns the weight associated with the <i class="arg">arc</i>. Throws an error if
the arc has no weight associated with it.</p></dd>
<dt><a name="20"><i class="arg">graphName</i> <b class="method">arc keys</b> <i class="arg">arc</i> <span class="opt">?<i class="arg">pattern</i>?</span></a></dt>
<dd><p>Returns a list of keys for the <i class="arg">arc</i>.
If the <i class="arg">pattern</i> is specified only the attributes whose names
match the pattern will be part of the returned list. The pattern is a
<b class="cmd">glob</b> pattern.</p></dd>
<dt><a name="21"><i class="arg">graphName</i> <b class="method">arc keyexists</b> <i class="arg">arc</i> <i class="arg">key</i></a></dt>
<dd><p>Return true if the specified <i class="arg">key</i> exists for the <i class="arg">arc</i>.</p></dd>
<dt><a name="22"><i class="arg">graphName</i> <b class="method">arc insert</b> <i class="arg">start</i> <i class="arg">end</i> <span class="opt">?<i class="arg">child</i>?</span></a></dt>
<dd><p>Insert an arc named <i class="arg">child</i> into the graph beginning at the node
<i class="arg">start</i> and ending at the node <i class="arg">end</i>. If the name of the new
arc is not specified the system will generate a unique name of the
form <em>arc</em><i class="arg">x</i>.</p></dd>
<dt><a name="23"><i class="arg">graphName</i> <b class="method">arc lappend</b> <i class="arg">arc</i> <i class="arg">key</i> <i class="arg">value</i></a></dt>
<dd><p>Appends a <i class="arg">value</i> (as a list) to one of the keyed values
associated with an <i class="arg">arc</i>. Returns the new value given to the
attribute <i class="arg">key</i>.</p></dd>
<dt><a name="24"><i class="arg">graphName</i> <b class="method">arc rename</b> <i class="arg">arc</i> <i class="arg">newname</i></a></dt>
<dd><p>Renames the arc <i class="arg">arc</i> to <i class="arg">newname</i>. An error is thrown if
either the arc does not exist, or a arc with name <i class="arg">newname</i> does
exist. The result of the command is the new name of the arc.</p></dd>
<dt><a name="25"><i class="arg">graphName</i> <b class="method">arc set</b> <i class="arg">arc</i> <i class="arg">key</i> <span class="opt">?<i class="arg">value</i>?</span></a></dt>
<dd><p>Set or get one of the keyed values associated with an arc.
An arc may have any number of keyed values associated with it.
If <i class="arg">value</i> is not specified, this command returns the current value assigned to the key;
if <i class="arg">value</i> is specified, this command assigns that value to the key, and returns
that value.</p></dd>
<dt><a name="26"><i class="arg">graphName</i> <b class="method">arc setunweighted</b> <span class="opt">?<i class="arg">weight</i>?</span></a></dt>
<dd><p>Sets the weight of all arcs without a weight to <i class="arg">weight</i>. Returns
the empty string as its result. If not present <i class="arg">weight</i> defaults
to <b class="const">0</b>.</p></dd>
<dt><a name="27"><i class="arg">graphName</i> <b class="method">arc setweight</b> <i class="arg">arc</i> <i class="arg">weight</i></a></dt>
<dd><p>Sets the weight of the <i class="arg">arc</i> to <i class="arg">weight</i>. Returns <i class="arg">weight</i>.</p></dd>
<dt><a name="28"><i class="arg">graphName</i> <b class="method">arc unsetweight</b> <i class="arg">arc</i></a></dt>
<dd><p>Removes the weight of the <i class="arg">arc</i>, if present. Does nothing
otherwise. Returns the empty string.</p></dd>
<dt><a name="29"><i class="arg">graphName</i> <b class="method">arc hasweight</b> <i class="arg">arc</i></a></dt>
<dd><p>Determines if the <i class="arg">arc</i> has a weight associated with it.  The
result is a boolean value, <b class="const">True</b> if a weight is defined, and
<b class="const">False</b> otherwise.</p></dd>
<dt><a name="30"><i class="arg">graphName</i> <b class="method">arc source</b> <i class="arg">arc</i></a></dt>
<dd><p>Return the node the given <i class="arg">arc</i> begins at.</p></dd>
<dt><a name="31"><i class="arg">graphName</i> <b class="method">arc target</b> <i class="arg">arc</i></a></dt>
<dd><p>Return the node the given <i class="arg">arc</i> ends at.</p></dd>
<dt><a name="32"><i class="arg">graphName</i> <b class="method">arc nodes</b> <i class="arg">arc</i></a></dt>
<dd><p>Return the nodes the given <i class="arg">arc</i> begins and ends at,
as a two-element list.</p></dd>
<dt><a name="33"><i class="arg">graphName</i> <b class="method">arc move-source</b> <i class="arg">arc</i> <i class="arg">newsource</i></a></dt>
<dd><p>Changes the source node of the arc to <i class="arg">newsource</i>. It can be said
that the arc rotates around its target node.</p></dd>
<dt><a name="34"><i class="arg">graphName</i> <b class="method">arc move-target</b> <i class="arg">arc</i> <i class="arg">newtarget</i></a></dt>
<dd><p>Changes the target node of the arc to <i class="arg">newtarget</i>. It can be said
that the arc rotates around its source node.</p></dd>
<dt><a name="35"><i class="arg">graphName</i> <b class="method">arc move</b> <i class="arg">arc</i> <i class="arg">newsource</i> <i class="arg">newtarget</i></a></dt>
<dd><p>Changes both source and target nodes of the arc to <i class="arg">newsource</i>,
and <i class="arg">newtarget</i> resp.</p></dd>
<dt><a name="36"><i class="arg">graphName</i> <b class="method">arc unset</b> <i class="arg">arc</i> <i class="arg">key</i></a></dt>
<dd><p>Remove a keyed value from the arc <i class="arg">arc</i>. The method will do
nothing if the <i class="arg">key</i> does not exist.</p></dd>
<dt><a name="37"><i class="arg">graphName</i> <b class="method">arc weights</b></a></dt>
<dd><p>Returns a dictionary whose keys are the names of all arcs which have a
weight associated with them, and the values are these weights.</p></dd>
<dt><a name="38"><i class="arg">graphName</i> <b class="method">arcs</b> <span class="opt">?-key <i class="arg">key</i>?</span> <span class="opt">?-value <i class="arg">value</i>?</span> <span class="opt">?-filter <i class="arg">cmdprefix</i>?</span> <span class="opt">?-in|-out|-adj|-inner|-embedding <i class="arg">node node...</i>?</span></a></dt>
<dd><p>Returns a list of arcs in the graph. If no restriction is specified a
list containing all arcs is returned. Restrictions can limit the list
of returned arcs based on the nodes that are connected by the arc, on
the keyed values associated with the arc, or both. A general filter
command can be used as well. The restrictions that involve connected
nodes take a variable number of nodes as argument, specified after the
name of the restriction itself.</p>
<p>The restrictions imposed by either <b class="option">-in</b>, <b class="option">-out</b>,
<b class="option">-adj</b>, <b class="option">-inner</b>, or <b class="option">-embedding</b> are applied
first. Specifying more than one of them is illegal.</p>
<p>After that the restrictions set via <b class="option">-key</b> (and
<b class="option">-value</b>) are applied. Specifying more than one <b class="option">-key</b>
(and <b class="option">-value</b>) is illegal. Specifying <b class="option">-value</b> alone,
without <b class="option">-key</b> is illegal as well.</p>
<p>Any restriction set through <b class="option">-filter</b> is applied
last. Specifying more than one <b class="option">-filter</b> is illegal.</p>
<p>Coming back to the restrictions based on a set of nodes, the command
recognizes the following switches:</p>
<dl class="doctools_definitions">
<dt><b class="option">-in</b></dt>
<dd><p>Return a list of all arcs whose target is one of the nodes in the set
of nodes. I.e. it computes the union of all incoming arcs of the nodes
in the set.</p></dd>
<dt><b class="option">-out</b></dt>
<dd><p>Return a list of all arcs whose source is one of the nodes in the set
of nodes. I.e. it computes the union of all outgoing arcs of the nodes
in the set.</p></dd>
<dt><b class="option">-adj</b></dt>
<dd><p>Return a list of all arcs adjacent to at least one of the nodes in the
set. This is the union of the nodes returned by <b class="option">-in</b> and
<b class="option">-out</b>.</p></dd>
<dt><b class="option">-inner</b></dt>
<dd><p>Return a list of all arcs which are adjacent to two of the nodes in
the set. This is the set of arcs in the subgraph spawned by the
specified nodes.</p></dd>
<dt><b class="option">-embedding</b></dt>
<dd><p>Return a list of all arcs adjacent to exactly one of the nodes in the
set. This is the set of arcs connecting the subgraph spawned by the
specified nodes to the rest of the graph.</p></dd>
</dl>
<p><em>Attention</em>: After the above options any word with a leading dash
which is not a valid option is treated as a node name instead of an
invalid option to error out on. This condition holds until either a
valid option terminates the list of nodes, or the end of the command
is reached, whichever comes first.</p>
<p>The remaining filter options are:</p>
<dl class="doctools_definitions">
<dt><b class="option">-key</b> <i class="arg">key</i></dt>
<dd><p>Limit the list of arcs that are returned to those arcs that have an
associated key <i class="arg">key</i>.</p></dd>
<dt><b class="option">-value</b> <i class="arg">value</i></dt>
<dd><p>This restriction can only be used in combination with
<b class="option">-key</b>. It limits the list of arcs that are returned to those
arcs whose associated key <i class="arg">key</i> has the value <i class="arg">value</i>.</p></dd>
<dt><b class="option">-filter</b> <i class="arg">cmdrefix</i></dt>
<dd><p>Limit the list of arcs that are returned to those arcs that pass the
test. The command in <i class="arg">cmdprefix</i> is called with two arguments, the
name of the graph object, and the name of the arc in question. It is
executed in the context of the caller and has to return a boolean
value. Arcs for which the command returns <b class="const">false</b> are removed
from the result list before it is returned to the caller.</p></dd>
</dl></dd>
<dt><a name="39"><i class="arg">graphName</i> <b class="method">lappend</b> <i class="arg">key</i> <i class="arg">value</i></a></dt>
<dd><p>Appends a <i class="arg">value</i> (as a list) to one of the keyed values
associated with the graph. Returns the new value given to the
attribute <i class="arg">key</i>.</p></dd>
<dt><a name="40"><i class="arg">graphName</i> <b class="method">node append</b> <i class="arg">node</i> <i class="arg">key</i> <i class="arg">value</i></a></dt>
<dd><p>Appends a <i class="arg">value</i> to one of the keyed values associated with an
<i class="arg">node</i>. Returns the new value given to the attribute <i class="arg">key</i>.</p></dd>
<dt><a name="41"><i class="arg">graphName</i> <b class="method">node attr</b> <i class="arg">key</i></a></dt>
<dd></dd>
<dt><a name="42"><i class="arg">graphName</i> <b class="method">node attr</b> <i class="arg">key</i> <b class="option">-nodes</b> <i class="arg">list</i></a></dt>
<dd></dd>
<dt><a name="43"><i class="arg">graphName</i> <b class="method">node attr</b> <i class="arg">key</i> <b class="option">-glob</b> <i class="arg">globpattern</i></a></dt>
<dd></dd>
<dt><a name="44"><i class="arg">graphName</i> <b class="method">node attr</b> <i class="arg">key</i> <b class="option">-regexp</b> <i class="arg">repattern</i></a></dt>
<dd><p>This method retrieves the value of the attribute named <i class="arg">key</i>, for
all nodes in the graph (matching the restriction specified via one of
the possible options) and having the specified attribute.</p>
<p>The result is a dictionary mapping from node names to the value of
attribute <i class="arg">key</i> at that node.
Nodes not having the attribute <i class="arg">key</i>, or not passing a
specified restriction, are not listed in the result.</p>
<p>The possible restrictions are:</p>
<dl class="doctools_options">
<dt><b class="option">-nodes</b></dt>
<dd><p>The value is a list of nodes. Only the nodes mentioned in this list
are searched for the attribute.</p></dd>
<dt><b class="option">-glob</b></dt>
<dd><p>The value is a glob pattern. Only the nodes in the graph whose names
match this pattern are searched for the attribute.</p></dd>
<dt><b class="option">-regexp</b></dt>
<dd><p>The value is a regular expression. Only the nodes in the graph whose
names match this pattern are searched for the attribute.</p></dd>
</dl></dd>
<dt><a name="45"><i class="arg">graphName</i> <b class="method">node degree</b> <span class="opt">?-in|-out?</span> <i class="arg">node</i></a></dt>
<dd><p>Return the number of arcs adjacent to the specified <i class="arg">node</i>. If one
of the restrictions <b class="option">-in</b> or <b class="option">-out</b> is given only the
incoming resp. outgoing arcs are counted.</p></dd>
<dt><a name="46"><i class="arg">graphName</i> <b class="method">node delete</b> <i class="arg">node</i> <span class="opt">?<i class="arg">node</i>...?</span></a></dt>
<dd><p>Remove the specified nodes from the graph.  All of the nodes' arcs
will be removed as well to prevent unconnected arcs.</p></dd>
<dt><a name="47"><i class="arg">graphName</i> <b class="method">node exists</b> <i class="arg">node</i></a></dt>
<dd><p>Return true if the specified <i class="arg">node</i> exists in the graph.</p></dd>
<dt><a name="48"><i class="arg">graphName</i> <b class="method">node get</b> <i class="arg">node</i> <i class="arg">key</i></a></dt>
<dd><p>Return the value associated with the key <i class="arg">key</i> for the <i class="arg">node</i>.</p></dd>
<dt><a name="49"><i class="arg">graphName</i> <b class="method">node getall</b> <i class="arg">node</i> <span class="opt">?<i class="arg">pattern</i>?</span></a></dt>
<dd><p>Returns a dictionary (suitable for use with [<b class="cmd">array set</b>])
for the <i class="arg">node</i>.
If the <i class="arg">pattern</i> is specified only the attributes whose names
match the pattern will be part of the returned dictionary. The pattern
is a <b class="cmd">glob</b> pattern.</p></dd>
<dt><a name="50"><i class="arg">graphName</i> <b class="method">node keys</b> <i class="arg">node</i> <span class="opt">?<i class="arg">pattern</i>?</span></a></dt>
<dd><p>Returns a list of keys for the <i class="arg">node</i>.
If the <i class="arg">pattern</i> is specified only the attributes whose names
match the pattern will be part of the returned list. The pattern is a
<b class="cmd">glob</b> pattern.</p></dd>
<dt><a name="51"><i class="arg">graphName</i> <b class="method">node keyexists</b> <i class="arg">node</i> <i class="arg">key</i></a></dt>
<dd><p>Return true if the specified <i class="arg">key</i> exists for the <i class="arg">node</i>.</p></dd>
<dt><a name="52"><i class="arg">graphName</i> <b class="method">node insert</b> <span class="opt">?<i class="arg">node</i>...?</span></a></dt>
<dd><p>Insert one or more nodes into the graph. The new nodes have no arcs
connected to them. If no node is specified one node will be inserted,
and the system will generate a unique name of the form
<em>node</em><i class="arg">x</i> for it.</p></dd>
<dt><a name="53"><i class="arg">graphName</i> <b class="method">node lappend</b> <i class="arg">node</i> <i class="arg">key</i> <i class="arg">value</i></a></dt>
<dd><p>Appends a <i class="arg">value</i> (as a list) to one of the keyed values
associated with an <i class="arg">node</i>. Returns the new value given to the
attribute <i class="arg">key</i>.</p></dd>
<dt><a name="54"><i class="arg">graphName</i> <b class="method">node opposite</b> <i class="arg">node</i> <i class="arg">arc</i></a></dt>
<dd><p>Return the node at the other end of the specified <i class="arg">arc</i>, which has
to be adjacent to the given <i class="arg">node</i>.</p></dd>
<dt><a name="55"><i class="arg">graphName</i> <b class="method">node rename</b> <i class="arg">node</i> <i class="arg">newname</i></a></dt>
<dd><p>Renames the node <i class="arg">node</i> to <i class="arg">newname</i>. An error is thrown if
either the node does not exist, or a node with name <i class="arg">newname</i> does
exist. The result of the command is the new name of the node.</p></dd>
<dt><a name="56"><i class="arg">graphName</i> <b class="method">node set</b> <i class="arg">node</i> <i class="arg">key</i> <span class="opt">?<i class="arg">value</i>?</span></a></dt>
<dd><p>Set or get one of the keyed values associated with a node. A node may have any
number of keyed values associated with it.  If <i class="arg">value</i> is not
specified, this command returns the current value assigned to the key;
if <i class="arg">value</i> is specified, this command assigns that value to the
key.</p></dd>
<dt><a name="57"><i class="arg">graphName</i> <b class="method">node unset</b> <i class="arg">node</i> <i class="arg">key</i></a></dt>
<dd><p>Remove a keyed value from the node <i class="arg">node</i>. The method will do
nothing if the <i class="arg">key</i> does not exist.</p></dd>
<dt><a name="58"><i class="arg">graphName</i> <b class="method">nodes</b> <span class="opt">?-key <i class="arg">key</i>?</span> <span class="opt">?-value <i class="arg">value</i>?</span> <span class="opt">?-filter <i class="arg">cmdprefix</i>?</span> <span class="opt">?-in|-out|-adj|-inner|-embedding <i class="arg">node</i> <i class="arg">node</i>...?</span></a></dt>
<dd><p>Return a list of nodes in the graph. Restrictions can limit the list
of returned nodes based on neighboring nodes, or based on the keyed
values associated with the node. The restrictions that involve
neighboring nodes have a list of nodes as argument, specified after
the name of the restriction itself.</p>
<p>The possible restrictions are the same as for method <b class="method">arcs</b>.
Note that while the exact meanings change slightly, as they operate on
nodes instead of arcs, the general behaviour is the same, especially
when it comes to the handling of words with a leading dash in node
lists.</p>
<p>The command recognizes:</p>
<dl class="doctools_definitions">
<dt><b class="option">-in</b></dt>
<dd><p>Return a list of all nodes with at least one outgoing arc ending in a
node found in the specified set of nodes. Alternatively specified as
the set of source nodes for the <b class="option">-in</b> arcs of the node set. The
<i class="term">incoming neighbours</i>.</p></dd>
<dt><b class="option">-out</b></dt>
<dd><p>Return a list of all nodes with at least one incoming arc starting in
a node found in the specified set of nodes. Alternatively specified as
the set of target nodes for the <b class="option">-out</b> arcs of the node
set. The <i class="term">outgoing neighbours</i>.</p></dd>
<dt><b class="option">-adj</b></dt>
<dd><p>This is the union of the nodes returned by <b class="option">-in</b> and
<b class="option">-out</b>. The <i class="term">neighbours</i>.</p></dd>
<dt><b class="option">-inner</b></dt>
<dd><p>The set of neighbours (see <b class="option">-adj</b> above) which are also in the
set of nodes. I.e. the intersection between the set of nodes and the
neighbours per <b class="option">-adj</b>.</p></dd>
<dt><b class="option">-embedding</b></dt>
<dd><p>The set of neighbours (see <b class="option">-adj</b> above) which are not in the
set of nodes. I.e. the difference between the neighbours as per
<b class="option">-adj</b>, and the set of nodes.</p></dd>
<dt><b class="option">-key</b> <i class="arg">key</i></dt>
<dd><p>Limit the list of nodes that are returned to those nodes that have an
associated key <i class="arg">key</i>.</p></dd>
<dt><b class="option">-value</b> <i class="arg">value</i></dt>
<dd><p>This restriction can only be used in combination with
<b class="option">-key</b>. It limits the list of nodes that are returned to those
nodes whose associated key <i class="arg">key</i> has the value <i class="arg">value</i>.</p></dd>
<dt><b class="option">-filter</b> <i class="arg">cmdrefix</i></dt>
<dd><p>Limit the list of nodes that are returned to those nodes that pass the
test. The command in <i class="arg">cmdprefix</i> is called with two arguments, the
name of the graph object, and the name of the node in question. It is
executed in the context of the caller and has to return a boolean
value. Nodes for which the command returns <b class="const">false</b> are removed
from the result list before it is returned to the caller.</p></dd>
</dl></dd>
<dt><a name="59"><i class="arg">graphName</i> <b class="method">get</b> <i class="arg">key</i></a></dt>
<dd><p>Return the value associated with the key <i class="arg">key</i> for the graph.</p></dd>
<dt><a name="60"><i class="arg">graphName</i> <b class="method">getall</b> <span class="opt">?<i class="arg">pattern</i>?</span></a></dt>
<dd><p>Returns a dictionary (suitable for use with [<b class="cmd">array set</b>])
for the whole graph.
If the <i class="arg">pattern</i> is specified only the attributes whose names
match the pattern will be part of the returned dictionary. The pattern
is a <b class="cmd">glob</b> pattern.</p></dd>
<dt><a name="61"><i class="arg">graphName</i> <b class="method">keys</b> <span class="opt">?<i class="arg">pattern</i>?</span></a></dt>
<dd><p>Returns a list of keys for the whole graph.
If the <i class="arg">pattern</i> is specified only the attributes whose names
match the pattern will be part of the returned list. The pattern is a
<b class="cmd">glob</b> pattern.</p></dd>
<dt><a name="62"><i class="arg">graphName</i> <b class="method">keyexists</b> <i class="arg">key</i></a></dt>
<dd><p>Return true if the specified <i class="arg">key</i> exists for the whole graph.</p></dd>
<dt><a name="63"><i class="arg">graphName</i> <b class="method">serialize</b> <span class="opt">?<i class="arg">node</i>...?</span></a></dt>
<dd><p>This method serializes the sub-graph spanned up by the <i class="arg">node</i>s. In
other words it returns a tcl value completely describing that
graph. If no nodes are specified the whole graph will be serialized.
This allows, for example, the transfer of graph objects (or parts
thereof) over arbitrary channels, persistence, etc.
This method is also the basis for both the copy constructor and
the assignment operator.</p>
<p>The result of this method has to be semantically identical over all
implementations of the graph interface. This is what will enable us to
copy graph data between different implementations of the same
interface.</p>
<p>The result is a list containing a multiple of three items, plus one!
In other words, '[llength $serial] % 3 == 1'. Valid values
include 1, 4, 7, ...</p>
<p>The last element of the list is a dictionary containing the attributes
associated with the whole graph.
Regarding the other elements; each triple consists of</p>
<ol class="doctools_enumerated">
<li><p>The name of the node to be described,</p></li>
<li><p>A dictionary containing the attributes associated with the node,</p></li>
<li><p>And a list describing all the arcs starting at that node.</p></li>
</ol>
<p>The elements of the arc list are lists containing three or four
elements each, i.e.</p>
<ol class="doctools_enumerated">
<li><p>The name of the arc described by the element,</p></li>
<li><p>A reference to the destination node of the arc. This reference is an
integer number given the index of that node in the main serialization
list. As that it is greater than or equal to zero, less than the
length of the serialization, and a multiple of three.
<em>Note:</em> For internal consistency no arc name may be used twice,
whether in the same node, or at some other node. This is a global
consistency requirement for the serialization.</p></li>
<li><p>And a dictionary containing the attributes associated with the arc.</p></li>
<li><p>The weight associated with the arc. This value is optional. Its
non-presence means that the arc in question has no weight associated
with it.</p>
<p><em>Note:</em> This information is new, compared to the
serialization of <b class="package"><a href="../../../../index.html#graph">graph</a></b> 2.3 and earlier. By making it an
optional element the new format is maximally compatible with the
old. This means that any graph not using weights will generate a
serialization which is still understood by the older graph package. A
serialization will not be understood any longer by the older packages
if, and only if the graph it was generated from actually has arcs with
weights.</p></li>
</ol>
<p>For all attribute dictionaries they keys are the names of the
attributes, and the values are the values for each name.</p>
<p><em>Note:</em> The order of the nodes in the serialization has no
relevance, nor has the order of the arcs per node.</p>
<pre class="doctools_example">
    # A possible serialization for the graph structure
    #
    #        d -----&gt; %2
    #       /         ^ \
    #      /         /   \
    #     /         b     \
    #    /         /       \
    #  %1 &lt;- a - %0         e
    #    ^         \\      /
    #     \\        c     /
    #      \\        \\  /
    #       \\        v v
    #        f ------ %3
    # is
    #
    # %3 {} {{f 6 {}}} %0 {} {{a 6 {}} {b 9 {}} {c 0 {}}} %1 {} {{d 9 {}}} %2 {} {{e 0 {}}} {}
    #
    # This assumes that the graph has neither attribute data nor weighted arcs.
</pre>
</dd>
<dt><a name="64"><i class="arg">graphName</i> <b class="method">set</b> <i class="arg">key</i> <span class="opt">?<i class="arg">value</i>?</span></a></dt>
<dd><p>Set or get one of the keyed values associated with a graph. A graph
may have any number of keyed values associated with it. If <i class="arg">value</i>
is not specified, this command returns the current value assigned to
the key; if <i class="arg">value</i> is specified, this command assigns that value
to the key.</p></dd>
<dt><a name="65"><i class="arg">graphName</i> <b class="method">swap</b> <i class="arg">node1</i> <i class="arg">node2</i></a></dt>
<dd><p>Swap the position of <i class="arg">node1</i> and <i class="arg">node2</i> in the graph.</p></dd>
<dt><a name="66"><i class="arg">graphName</i> <b class="method">unset</b> <i class="arg">key</i></a></dt>
<dd><p>Remove a keyed value from the graph. The method will do nothing if the
<i class="arg">key</i> does not exist.</p></dd>
<dt><a name="67"><i class="arg">graphName</i> <b class="method">walk</b> <i class="arg">node</i> <span class="opt">?-order <i class="arg">order</i>?</span> <span class="opt">?-type <i class="arg">type</i>?</span> <span class="opt">?-dir <i class="arg">direction</i>?</span> -command <i class="arg">cmd</i></a></dt>
<dd><p>Perform a breadth-first or depth-first walk of the graph starting at
the node <i class="arg">node</i> going in either the direction of outgoing or
opposite to the incoming arcs.</p>
<p>The type of walk, breadth-first or depth-first, is determined by the
value of <i class="arg">type</i>; <b class="const">bfs</b> indicates breadth-first,
<b class="const">dfs</b> indicates depth-first.  Depth-first is the default.</p>
<p>The order of the walk, pre-order, post-order or both-order is
determined by the value of <i class="arg">order</i>; <b class="const">pre</b> indicates
pre-order, <b class="const">post</b> indicates post-order, <b class="const">both</b> indicates
both-order. Pre-order is the default. Pre-order walking means that a
node is visited before any of its neighbors (as defined by the
<i class="arg">direction</i>, see below). Post-order walking means that a parent is
visited after any of its neighbors. Both-order walking means that a
node is visited before <em>and</em> after any of its neighbors. The
combination of a breadth-first walk with post- or both-order is illegal.</p>
<p>The direction of the walk is determined by the value of <i class="arg">dir</i>;
<b class="const">backward</b> indicates the direction opposite to the incoming
arcs, <b class="const">forward</b> indicates the direction of the outgoing arcs.</p>
<p>As the walk progresses, the command <i class="arg">cmd</i> will be evaluated at
each node, with the mode of the call (<b class="const">enter</b> or
<b class="const">leave</b>) and values <i class="arg">graphName</i> and the name of the current
node appended. For a pre-order walk, all nodes are <b class="const">enter</b>ed, for a
post-order all nodes are left. In a both-order walk the first visit of
a node <b class="const">enter</b>s it, the second visit <b class="const">leave</b>s it.</p></dd>
</dl>
</div>
<div id="section2" class="doctools_section"><h2><a name="section2">Changes for 2.0</a></h2>
<p>The following noteworthy changes have occurred:</p>
<ol class="doctools_enumerated">
<li><p>The API for accessing attributes and their values has been
simplified.</p>
<p>All functionality regarding the default attribute &quot;data&quot; has been
removed. This default attribute does not exist anymore. All accesses
to attributes have to specify the name of the attribute in
question. This backward <em>incompatible</em> change allowed us to
simplify the signature of all methods handling attributes.</p>
<p>Especially the flag <b class="option">-key</b> is not required anymore, even more,
its use is now forbidden. Please read the documentation for the arc
and node methods <b class="method">set</b>, <b class="method">get</b>, <b class="method">getall</b>,
<b class="method">unset</b>, <b class="method">append</b>, <b class="method">lappend</b>, <b class="method">keyexists</b>
and <b class="method">keys</b> for a description of the new API's.</p></li>
<li><p>The methods <b class="method">keys</b> and <b class="method">getall</b> now take an optional
pattern argument and will return only attribute data for keys matching
this pattern.</p></li>
<li><p>Arcs and nodes can now be renamed. See the documentation for the
methods <b class="method">arc rename</b> and <b class="method">node rename</b>.</p></li>
<li><p>The structure has been extended with API's for the serialization and
deserialization of graph objects, and a number of operations based on
them (graph assignment, copy construction).</p>
<p>Please read the documentation for the methods <b class="method">serialize</b>,
<b class="method">deserialize</b>, <b class="method">=</b>, and <b class="method">--&gt;</b>, and the
documentation on the construction of graph objects.</p>
<p>Beyond the copying of whole graph objects these new API's also enable
the transfer of graph objects over arbitrary channels and for easy
persistence.</p></li>
<li><p>A new method, <b class="method">attr</b>, was added to both <b class="method">arc</b> and
<b class="method">node</b> allowing the query and retrieval of attribute data
without regard to arc and node relationships.</p></li>
<li><p>Both methods <b class="method">arcs</b> and <b class="method">nodes</b> have been extended with
the ability to select arcs and nodes based on an arbitrary filtering
criterium.</p></li>
</ol>
</div>
<div id="section3" class="doctools_section"><h2><a name="section3">Bugs, Ideas, Feedback</a></h2>
<p>This document, and the package it describes, will undoubtedly contain
bugs and other problems.
Please report such in the category <em>struct :: graph</em> of the
<a href="http://core.tcl.tk/tcllib/reportlist">Tcllib Trackers</a>.
Please also report any ideas for enhancements you may have for either
package and/or documentation.</p>
<p>When proposing code changes, please provide <em>unified diffs</em>,
i.e the output of <b class="const">diff -u</b>.</p>
<p>Note further that <em>attachments</em> are strongly preferred over
inlined patches. Attachments can be made by going to the <b class="const">Edit</b>
form of the ticket immediately after its creation, and then using the
left-most button in the secondary navigation bar.</p>
</div>
<div id="keywords" class="doctools_section"><h2><a name="keywords">Keywords</a></h2>
<p><a href="../../../../index.html#adjacent">adjacent</a>, <a href="../../../../index.html#arc">arc</a>, <a href="../../../../index.html#cgraph">cgraph</a>, <a href="../../../../index.html#degree">degree</a>, <a href="../../../../index.html#edge">edge</a>, <a href="../../../../index.html#graph">graph</a>, <a href="../../../../index.html#loop">loop</a>, <a href="../../../../index.html#neighbour">neighbour</a>, <a href="../../../../index.html#node">node</a>, <a href="../../../../index.html#serialization">serialization</a>, <a href="../../../../index.html#subgraph">subgraph</a>, <a href="../../../../index.html#vertex">vertex</a></p>
</div>
<div id="category" class="doctools_section"><h2><a name="category">Category</a></h2>
<p>Data structures</p>
</div>
<div id="copyright" class="doctools_section"><h2><a name="copyright">Copyright</a></h2>
<p>Copyright &copy; 2002-2009,2019 Andreas Kupries &lt;andreas_kupries@users.sourceforge.net&gt;</p>
</div>
</div></body></html>
